//
//  LGOrderIndex.swift
//  LeGou
//
//  Created by lxm on 2022/9/21.
//

import UIKit

class LGOrderIndex: ZMViewController, LemonIndexHeaderViewDelegate {

    //MARK:--------------------属性--------------------
    
    //MARK:--------------------UI控件--------------------
    var indexView = LemonIndexHeaderView().then { v in
        if AppHelper.appVerify() {
            v.data = ["乐购商城", "自营商城"]
        } else {
            v.data = ["知识付费", "自营商城"]
        }
        v.layer.cornerRadius = 16
        v.backgroundColor = .white
    }
    
    let contentV = UIView()
    
    let lessonVC = Orders().then { vc in
        if AppHelper.appVerify() {
            vc.type = .lgMall
        } else {
            vc.type = .lesson
        }
    }
    
    let lgMallVC = Orders().then { vc in
        vc.type = .lgMall
    }
    //MARK:--------------------生命周期--------------------
    override func viewDidLoad() {
        super.viewDidLoad()
        setUI()
        addConstraints()
        bindAction()
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        indexView.layoutIfNeeded()
        indexView.layoutSubviews()
        indexView.collectionView.reloadData()
    }
    //MARK:--------------------UI--------------------
    func setUI() {
        title = "乐购商城订单"
        view.addSubview(indexView)
        indexView.delegate = self
        view.backgroundColor = "#F5F5F5".zm.hex()
        view.addSubview(contentV)
        
        addChild(lessonVC)
        addChild(lgMallVC)

        contentV.addSubview(lessonVC.view)
    }
    func addConstraints() {
        indexView.snp.makeConstraints { make in
            make.width.equalTo(164)
            make.centerX.equalToSuperview()
            make.height.equalTo(38)
            make.top.equalToSuperview().offset(16)
        }
        
        contentV.snp.makeConstraints { make in
            make.top.equalTo(indexView.snp.bottom).offset(18)
            make.left.right.bottom.equalToSuperview()
        }
        
        lessonVC.view.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
    }
    
    
    
    //MARK:--------------------methods--------------------
    func bindAction() {
        
    }

    //MARK:--------------------delegate--------------------
    func shouldSelect(indexView : LemonIndexHeaderView, indexpath: IndexPath) -> Bool {
        if indexpath.row == 0 {
            contentV.addSubview(lessonVC.view)
            lessonVC.view.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }
        } else {
            contentV.addSubview(lgMallVC.view)
            lgMallVC.view.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }
        }
        return true
    }
}
